﻿using System.Windows.Controls;

namespace System.Windows
{
    public static class UIElementExtension
    {
        public static void SetCanvasLocation(this UIElement element, Point location)
        {
            var left = location.X;
            var top = location.Y;
            SetCanvasLeft(element, left);
            SetCanvasTop(element, top);
        }

        public static void SetCanvasLeft(this UIElement element, double left)
        {
            if(double.IsNegativeInfinity(left) == false &&
               double.IsPositiveInfinity(left) == false)
            {
                Canvas.SetLeft(element, left);
            }
        }

        public static void SetCanvasTop(this UIElement element, double top)
        {
            if (double.IsNegativeInfinity(top) == false &&
               double.IsPositiveInfinity(top) == false)
            {
                Canvas.SetTop(element, top);
            }
        }
    }
}
